<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html>
<head>
<title>Introduction to Qt4 toolkit</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="Qt, Trolltech, installing qt, qt4.2.3, installation, C++">
<meta name="description" content="This chapter is an introduction to the Qt4 toolkit">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

<script type="text/javascript" src="/lib/jquery.js"></script>
<script type="text/javascript" src="/lib/common.js"></script>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-5536206-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

</head>

<body>

<div class="container2">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<div class="content2">


<a href="/" title="Home">Home</a>&nbsp;
<a href="..">Contents</a>


<h1>Introduction to Qt4 toolkit</h1>

<p>
In this part of the Qt4 tutorial, we will introduce the Qt4 library.
We will install the Qt4 library and create our first small Qt4 application.
</p>

<div class="big_hor">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-9706709751191532";
/* big_horizontal */
google_ad_slot = "2904953388";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>

<h2>Qt Development Frameworks</h2>

<p>
Qt toolkit was initially developed by Trolltech, a Norwegian software company.
In 2008 the company was acquired by Nokia. The company was renamed to 
Qt Development Frameworks. In August 2012 a Finnish development company Digia
acquired Qt software technologies from Nokia. Meanwhile a Qt Project was created
in which the development of open source Qt continues. The website for the open source
Qt toolkit can be found at <a href="http://qt-project.org/">qt-project.org</a>. 
</p>


<h2>Qt toolkit</h2>

<p>
Qt is a cross-platform application development framework. Some of the
well known applications developed with Qt are KDE, Opera, Google Earth, Skype,
VLC, Maya or Mathematica. Qt was first publicly released on May 1995. 
It is dual licensed. It can be used for creating open source applications 
as well as commercial ones. Qt toolkit is a very powerful toolkit. It is well established 
in the open source community. Thousands of open source developers use Qt 
all over the world. 
</p>



<h2>Download</h2>

<p>
We go to the <a href="http://qt-project.org/downloads">download</a> 
page. We can have either an online or offline installation. It
is possible to choose to download the whole Qt4 SDK or get the
parts of the SDK separatly. The complete SDK has some 
additional development tools. These can be also downloaded later.
In this page we will show how to install Qt libraries 4.8.3 for Linux. 
</p>

<pre>
$ ls qt-everywhere-opensource-src-4.8.3.tar.gz 
qt-everywhere-opensource-src-4.8.3.tar.gz
</pre>

<p>
From the download page we download the Qt4 libraries. 
</p>

<pre>
$ tar -xzvf qt-everywhere-opensource-src-4.8.3.tar.gz 
</pre>

<p>
The command will decompress all the files to a directory 
qt-everywhere-opensource-src-4.8.3.
</p>

<pre>
$ du -hs qt-everywhere-opensource-src-4.8.3
685M    qt-everywhere-opensource-src-4.8.3
</pre>

<p>
The size of the directory is now 685 MB.
</p>

<pre>
$ cd qt-everywhere-opensource-src-4.8.3/
</pre>

<p>
We go to the created directory.
Now it is time to carefully read the README and the INSTALL file. 
There we will find detailed installation instructions.
The installation is easy and straightforward. 
</p>


<h2>Install</h2>

<p>
We install the library the classic way. On Unix systems, installation of a 
software is divided into three steps.
</p>

<ul>
<li>Configuration</li>
<li>Building</li>
<li>Installation</li>
</ul>

<pre>
$ ./configure -prefix /usr/local/qt4
Which edition of Qt do you want to use ?

Type 'c' if you want to use the Commercial Edition.
Type 'o' if you want to use the Open Source Edition.
</pre>

<p>
First we run the configure script. The script will ask whether
we want the commercial or open source edition of the Qt4 library.
The script will configure the library for our machine type. By default, 
the qt will be installed in /usr/local/Trolltech/Qt-4.8.3 directory. This can be changed 
by the -prefix parameter of the configure script. We install the library
into the /usr/local/qt4 directory. Note that the installation word has two meanings here. 
It is the whole process consisting of all three steps. And it also means 'moving files 
to specific directories', which is the last, third step.
</p>

<pre>
This is the  Open Source Edition.

You are licensed to use this software under the terms of
the Lesser GNU General Public License (LGPL) versions 2.1.
You are also licensed to use this software under the terms of
the GNU General Public License (GPL) versions 3.

Type '3' to view the GNU General Public License version 3.
Type 'L' to view the Lesser GNU General Public License version 2.1.
Type 'yes' to accept this license offer.
Type 'no' to decline this license offer.

Do you accept the terms of either license? yes
</pre>

<p>
Confirming licence agreement.
</p>

<pre>
Qt is now configured for building. Just run 'make'.
Once everything is built, you must run 'make install'.
Qt will be installed into /usr/local/qt4

To reconfigure, run 'make confclean' and 'configure'.
</pre>

<p>
We get this message after the configure script finishes.
</p>

<pre>
$ make
</pre>

<p>
We use the <code>make</code> command to start the build process.
The building of the Qt toolkit can take several hours. It depends on the 
power of your processor.
</p>

<p>
The last step is installing, or moving files to the directories.
</p>

<pre>
sudo make install
</pre>

<p>
This command finishes the installation process. The library is now installed 
in /usr/local/qt4 directory. 
</p>

<pre>
$ du -sh /usr/local/qt4
435M    /usr/local/qt4
</pre>

<p>
The size of the directory is 435 MB. As we can 
see, Qt is a huge library.
</p>

<p>
The last thing that we do, is adding the qt4 path to the PATH system variable.
The bash users, need to edit the either the <i>.profile</i> file or
the <i>.bashrc</i> file.
</p>

<pre>
PATH=/usr/local/qt4/bin:$PATH
export PATH
</pre>

<p>
We have added a path to the bin directory of the Qt4 library to the 
PATH environment variable. The changes will be active after another login.
</p>


<h2>Testing a small example</h2>

<p>
Finally we will write a small code example. 
</p>


<pre class="code">
#include &lt;QApplication&gt;
#include &lt;QWidget&gt;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWidget window;

    window.resize(250, 150);
    window.setWindowTitle("Simple example");
    window.show();

    return app.exec();
}
</pre>

<p>
To build this example, we will use a very handy tool called <i>qmake</i>.
</p>

<pre>
qmake -project
qmake
make
</pre>


<p>
If the qt4 installation directory is not a part of the PATH variable,
we can provide the full path to the qmake tool.
</p>

<pre>
/usr/local/qt4/bin/qmake -project
/usr/local/qt4/bin/qmake
make
</pre>

<img src="/img/gui/qt4/simple.png" alt="Simple example">
<div class="figure">Figure: Simple example</div>

<p>
Installation finished OK.
</p>


<p>
This chapter was an introduction to the Qt4 library.
</p>

<div class="center"> 
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* horizontal */
google_ad_slot = "1734478269";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script> 
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script> 
</div> 
<br>


<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="..">Contents</a></span> ‡ 
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>


<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified September 26, 2012  <span class="copyright">&copy; 2007 - 2013 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>

</html>

